﻿@page "/admin/armanage"
@layout AdminLayout
@attribute [Authorize]
@inject HttpClient HttpClient
@inject IPopupService PopupService

<PageTitle>年评管理</PageTitle>


<div style="display: -webkit-box;">
    <MSelect HideDetails="@true" MinWidth="135" Clearable="@true" Label="分类" Placeholder="请选择分类" Solo Dense
             TItem="SelectItem" TItemValue="string" TValue="string" Items="@selectItems" ItemText="u => u.Label"
             ItemValue="u => u.Value" Style="margin-right: 20px;width: 120px;"
             OnSelectedItemUpdate="@(e=>VcateSelectedChange(e.Value))" OnClearClick="ClearVcate">
    </MSelect>
    <MButton Color="primary" OnClick="ShowAddForm">
        <MIcon Left>mdi-plus</MIcon>
        添加
    </MButton>
</div>

@*数据表格*@
<MDataTable FixedRight Headers="headers" Items="annualReviewList" Width="@("100%")"
            ItemKey="r=>r.Id.ToString()" Class="elevation-3"
            Style="height: 550px; overflow-y: auto;margin-top: 15px;">
    <ItemColContent>
        @if (context.Header.Value == "actions")
        {
            <MIcon Small Class="mr-2" OnClick="()=>EditItem(context.Item)">mdi-pencil</MIcon>
            <MIcon Small OnClick="()=>DeleteItem(context.Item.Id)">mdi-delete</MIcon>
        }
        else
        {
            @context.Value
        }
    </ItemColContent>
</MDataTable>



@* 编辑对话框 *@
<MDialog @bind-Value="_dialogEdit" MaxWidth="600">
    <MCard>
        <MCardTitle>
            <span class="text-h5">编辑</span>
        </MCardTitle>
        <MCardText>
            <MContainer>
                <MTextField TValue="uint" Type="number" @bind-Value="_editedItem.Year"
                            Label="年份" Placeholder="年份" TextColor="green"
                            HideDetails="@true"></MTextField>
                <MTextField TValue="string" @bind-Value="_editedItem.Comment"
                            Label="点评" Placeholder="点评" TextColor="green"
                            HideDetails="@true"></MTextField>

            </MContainer>
        </MCardText>

        <MCardActions>
            <MSpacer></MSpacer>
            <MButton Color="blue darken-1" Text OnClick="Close">
                取消
            </MButton>
            <MButton Color="blue darken-1" Text OnClick="SubmitEdit">
                提交
            </MButton>
        </MCardActions>
    </MCard>
</MDialog>


@* 添加对话框 *@
<MDialog @bind-Value="_dialogAdd" MaxWidth="600">
    <MCard>
        <MCardTitle>
            <span class="text-h5">添加</span>
        </MCardTitle>
        <MCardText>
            <MContainer>
                <MTextField TValue="uint" Type="number" @bind-Value="_editedItem.Year"
                            Label="年份" Placeholder="年份" TextColor="green"
                            HideDetails="@true"></MTextField>
                <MTextField TValue="string" @bind-Value="_editedItem.Comment"
                            Label="点评" Placeholder="点评" TextColor="green"
                            HideDetails="@true"></MTextField>


            </MContainer>
        </MCardText>

        <MCardActions>
            <MSpacer></MSpacer>
            <MButton Color="blue darken-1" Text OnClick="Close">
                取消
            </MButton>
            <MButton Color="blue darken-1" Text OnClick="SubmitAddAsync">
                提交
            </MButton>
        </MCardActions>
    </MCard>
</MDialog>


@* 删除对话框 *@
<MDialog @bind-Value="_dialogDelete" MaxWidth="500">
    <MCard>
        <MCardTitle Class="text-h6">确定要删除此项吗?</MCardTitle>
        <MCardActions>
            <MSpacer></MSpacer>
            <MButton Color="blue darken-1" Text OnClick="CloseDelete">取消</MButton>
            <MButton Color="blue darken-1" Text OnClick="DeleteItemConfirmAsync">确定</MButton>
            <MSpacer></MSpacer>
        </MCardActions>
    </MCard>
</MDialog>
